package com.moon.game.util;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;


public final class SizeCalculator {
	
	public static int calcSize(java.io.Serializable o) { 
		int ret = 0; 

		ByteArrayOutputStream buf = new ByteArrayOutputStream(); 
		ObjectOutputStream os = null; 
		try { 
			os = new ObjectOutputStream(buf); 
			os.writeObject(o); 
			ret = buf.size(); 
		} catch (IOException e) { 
			// No need handle this exception 
			e.printStackTrace(); 
			ret = -1; 
		} finally { 
			try { 
				os.close(); 
				buf.close();
			} catch (Exception e) { 
			} 
		} 
		return ret;
	}
	/*
	public static void main(String[] args) {
		HashMap testMap = new HashMap();
		// 196
		//testMap.put(1, "test");
		//testMap.put(2, "test");
		//testMap.put(3, "test");
		testMap.put((byte)1, "test");
		testMap.put((byte)2, "test");
		testMap.put((byte)3, "test");
		testMap.put((byte)4, "test");
		testMap.put((byte)5, "test");
		testMap.put((byte)6, "test");
		System.out.println(SizeCalculator.calcSize(testMap));
		Test test = new Test();
		test.setA1("test");
		test.setA2("test");
		test.setA3("test");
		test.setA4("test");
		test.setA5("test");
		test.setA6("test");
		System.out.println(SizeCalculator.calcSize(test));
		
		
	}*/
}
